/***************************************************************************************************
 *
 * Project: HZFlashcards
 *
 * Class: Actions
 *
 * File name: Actions.java
 *
 * Sep 2, 2007
 *
 **************************************************************************************************/

package com.eastmountain.chinese.gui.controllers;

import java.awt.event.ActionEvent;
import java.net.URL;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

import com.eastmountain.chinese.gui.HanZiDisplayPanel;

/***************************************************************************************************
 *
 * CLASS ToolBarActions
 *
 **************************************************************************************************/

@SuppressWarnings("serial")
public class ToolBarActions extends AbstractAction {

    private HanZiDisplayPanel hanZiDisplayPanel;

    Vector<AbstractButton> toolBarButtons;

    private Border emptyBorder = BorderFactory.createEmptyBorder( 2, 2, 2, 2 );

    private Border etchedBorder
        = BorderFactory.createBevelBorder( BevelBorder.LOWERED );
    private Border compoundBorder
        = BorderFactory.createCompoundBorder( emptyBorder, etchedBorder );


    public ToolBarActions( HanZiDisplayPanel hanZiDisplayPanel ) {

        this.hanZiDisplayPanel = hanZiDisplayPanel;

    }

    /***********************************************************************************************
     *
     * actionPerformed
     *
     **********************************************************************************************/

    public void actionPerformed( ActionEvent event ) {

        System.out.println( "==== ToolBarActions.actionPerformed invoked with: "
                            + event.getActionCommand());

        String command = event.getActionCommand();

        if ( ToolBarButtons.PREVIOUS_LESSON.buttonName().equals( command ) ) {

            hanZiDisplayPanel.previousLesson();

            System.out.println( "+====+ " + ToolBarButtons.PREVIOUS_LESSON.buttonName() );

        } else if ( ToolBarButtons.PREVIOUS.buttonName().equals( command ) ) {

            hanZiDisplayPanel.previous();

            System.out.println( "+====+ " + ToolBarButtons.PREVIOUS.buttonName() );

        } else if ( ToolBarButtons.NEXT.buttonName().equals( command ) ) {

            hanZiDisplayPanel.next();

            System.out.println( "+====+ " + ToolBarButtons.NEXT.buttonName() );

        } else if ( ToolBarButtons.NEXT_LESSON.buttonName().equals( command ) ) {

            hanZiDisplayPanel.nextLesson();

            System.out.println( "+====+ " + ToolBarButtons.NEXT_LESSON.buttonName() );

        } else if ( ToolBarButtons.FLIP.buttonName().equals( command ) ) {

            hanZiDisplayPanel.flip();

            System.out.println( "+====+ " + ToolBarButtons.FLIP.buttonName() );

        } else if ( ToolBarButtons.REVIEW.buttonName().equals( command ) ) {

            hanZiDisplayPanel.question();

            System.out.println( "+====+ " + ToolBarButtons.REVIEW.buttonName() );

        } else if ( ToolBarButtons.SHUFFLE.buttonName().equals( command ) ) {

        	//TODO DIASABLE NEXT LESSON ETC.
        	
            hanZiDisplayPanel.shuffle();

            System.out.println( "+====+ " + ToolBarButtons.SHUFFLE.buttonName() );
            
        }  else if ( ToolBarButtons.PLAY.buttonName().equals( command ) ) {

            //TODO DIASABLE NEXT LESSON ETC.
            
            if ( ToolBarButtons.PLAY.toolBarButton().isSelected() ) {

                System.out.println( "+====+ " + ToolBarButtons.PLAY.buttonName() 
                                    + " : Selected");
           
                hanZiDisplayPanel.playDrill();
            
            } else  {

                System.out.println( "+====+ " + ToolBarButtons.PLAY.buttonName() 
                                    + " : Not Selected");
           
                hanZiDisplayPanel.stopPlay();
            
            }
            
        }


    }

    public void enableDisableButton( ToolBarButtons button, boolean enable ) {
       
        if ( enable ) {
            
            button.toolBarButton().setEnabled( true );
        
        } else {
            
            button.toolBarButton().setEnabled( false );
            
        }
        
    }

    public Vector<AbstractButton> setUpButtons() {

        toolBarButtons = new Vector<AbstractButton>();

        for ( ToolBarButtons button : ToolBarButtons.values() ) {

            button.toolBarButton().setAction( this );
            button.toolBarButton().setActionCommand( button.buttonName() );

            //button.toolBarButton().setBorder( compoundBorder );
            button.toolBarButton().setIcon( button.buttonIcon() );
            button.toolBarButton().setToolTipText( button.buttonToolTip() );

            toolBarButtons.add( button.toolBarButton() );

        }

        return toolBarButtons;

    }

}


